package ar.edu.unicen.pladema.ui.mywidgets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import ar.edu.unicen.pladema.main.SWTUtils;
import ar.edu.unicen.pladema.resources.ResourceManager;
import ar.edu.unicen.pladema.ui.panel.AbstractPanel;

public class OffsetPanel extends AbstractPanel {
	private Group group;
	private int width;
	private int height;
	private Label anchoL;
	private Label altoL;
	private Text ancho;
	private Text alto;
	
	public OffsetPanel(Composite parent) {
		super(parent);
	}

	@Override
	protected void createWidgets() {
		group = new Group(this, SWT.SHADOW_ETCHED_IN);
		anchoL = new Label(group, SWT.NONE);
		ancho = new Text(group, SWT.BORDER);
		altoL = new Label(group, SWT.NONE);
		alto = new Text(group, SWT.BORDER);

		group.setText(ResourceManager.getInstance().getText("OFFSET_TITLE"));
		anchoL.setText(ResourceManager.getInstance().getText("OFFSET_WIDTH"));
		altoL.setText(ResourceManager.getInstance().getText("OFFSET_HEIGHT"));
	}

	@Override
	protected void layoutWidgets() {
		this.setLayout(new FillLayout(SWT.VERTICAL));
		group.setLayout(new FormLayout());
		anchoL.setLayoutData(SWTUtils.createTopFormData());
		ancho.setLayoutData(SWTUtils.createBelowFormData(anchoL));
		altoL.setLayoutData(SWTUtils.createBelowFormData(ancho));
		alto.setLayoutData(SWTUtils.createBelowFormData(altoL));
	}
	public void setWidth(int width) {
		this.width = width;
		this.ancho.setText(Integer.toString(width));
	}

	public void setHeight(int height) {
		this.height = height;
		this.alto.setText(Integer.toString(height));
	}

	/**
	 * @return the width
	 */
	public int getWidth() {
		try {
			width = Integer.parseInt(ancho.getText());
			return width;
		} catch (Exception e) {
			
		}
		ancho.setText(Integer.toString(width));
		return width;
	}

	/**
	 * @return the height
	 */
	public int getHeight() {
		try {
			height = Integer.parseInt(alto.getText());
			return height;
		} catch (Exception e) {
			
		}
		alto.setText(Integer.toString(height));
		return height;
	}
}
